package com.tbvtc.agriculturalcreditchainserver2025.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tbvtc.agriculturalcreditchainserver2025.entity.UserDevice;
import com.tbvtc.agriculturalcreditchainserver2025.mapper.UserDeviceMapper;
import com.tbvtc.agriculturalcreditchainserver2025.service.IUserDeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户设备表 服务实现类
 * </p>
 *
 * @author syh
 * @since 2025-04-15
 */
@Service
public class UserDeviceServiceImpl extends ServiceImpl<UserDeviceMapper, UserDevice> implements IUserDeviceService {
@Autowired
 private  UserDeviceMapper userDeviceMapper;
    @Override
    public String insert(UserDevice userDevice) {
        LambdaQueryWrapper<UserDevice> queryWrapper = new LambdaQueryWrapper<UserDevice>()
                .select(UserDevice::getId)
                .eq(UserDevice::getUserName,userDevice.getUserName());
       UserDevice list = userDeviceMapper.selectOne(queryWrapper);
       if (list == null){
          userDeviceMapper.insert(userDevice);
          return userDevice.getId();
       }
       return list.getId();
    }
}
